#include<stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef int SElemType_t;

struct Stack
{
    SElemType_t *stack;
    int size;
    int top; //栈顶的位置
};
struct Stack *manager;

void stack_init(int size)
{
    //1 申请栈管理结构体
    manager = malloc(sizeof(struct Stack));
    manager->size = size;

    //2 申请连续的堆空间存储 栈元素
    manager->stack = calloc(manager->size,sizeof(SElemType_t));

    manager->top = -1;
}

//判断栈是否为满
bool isFull()
{
    // if(manager->top == manager->size - 1)
    //     return true;
    // else 
    //     return false;

    return manager->top == manager->size - 1;
}

//入栈  插入数据  尾插
bool push(SElemType_t data)
{
    if(isFull()){
        printf("isFull\n");
        return false;
    }
    manager->stack[++manager->top] = data;

    return true;
}

bool isEmpty()
{
    return manager->top == -1;
}

//出栈  删除数据  尾删   为何出栈？？？？ 就是要对数据利用
bool pop(SElemType_t *data)
{
    //1 先判断是否为空
    if(isEmpty()){
        return false;
    }
    //2 先获取数据
    *data = manager->stack[manager->top];
    //3 偏移top
    manager->top--;

    return true;
}


int main()
{
    stack_init(10);

    int data = 78;
    //入栈
    while (1)
    {
        /* code */
        push(data%8);

        data  =  data / 8;

        if(data == 0)
            break;
    }
    
    

    while (1)
    {
        SElemType_t data;
        bool ret = pop(&data);
        if(ret == false)
            break;

        printf("%d",data);
    }
    
    printf("\n");
    
    return 0;
}